package com.chilly.bean;

import org.junit.jupiter.api.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by Chilly Cui on 2020/9/25.
 */
public class LifeBean {
    private String name;

    public LifeBean() {
        System.out.println("LifeBean()构造函数");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        System.out.println("setName()");
        this.name = name;
    }

    public void init() {
        System.out.println("this is init of lifeBean");
    }

    public void destory() {
        System.out.println("this is destory of lifeBean " + this);
    }

    @Test
    public void test() {

        AbstractApplicationContext container =
                new ClassPathXmlApplicationContext("life.xml");

        LifeBean life1 = (LifeBean) container.getBean("life_singleton");
        System.out.println(life1);

        LifeBean life2 = (LifeBean) container.getBean("life_singleton");
        System.out.println(life2);

        container.close();
    }

}
